package vn.edu.saigontech.ncms.web.teacher.report;

import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.LinkedList;

import vn.edu.saigontech.ncms.model.enumeration.Nationality;
import vn.edu.saigontech.ncms.model.enumeration.TeacherType;
import vn.edu.saigontech.ncms.model.info.Offering;

@SuppressWarnings("serial")
public class TeacherTeachingDetail implements Serializable {
	private Long teacherId;
	private String sortName;
	private String teacher;
	private String firstName;
	private String midName;
	private String lastName;
	private TeacherType teacherType;
	private Nationality nationality;

	private LinkedList<OfferingTeachingDetail> details = new LinkedList<OfferingTeachingDetail>();

	public TeacherTeachingDetail(Long id, String sortName, String teacher, TeacherType teacherType, Nationality nationality) {
		this.teacherId = id;
		this.sortName = sortName;
		this.teacher = teacher;
		this.teacherType = teacherType;
		this.nationality = nationality;
	}
	
	public void removeInvalidDetails() {
		Collection<OfferingTeachingDetail> invalid = new LinkedHashSet<OfferingTeachingDetail>();
		for (OfferingTeachingDetail detail : this.details) {
			if (detail.getSessions() < 1)
				invalid.add(detail);
		}
		this.details.removeAll(invalid);
	}

	public OfferingTeachingDetail getDetail(Offering offering) {
		for (OfferingTeachingDetail detail : this.details) {
			if (detail.getOffering().equals(offering)) {
				return detail;
			}
		}
		return null;
	}

	public OfferingTeachingDetail getDetail(String offeringName) {
		for (OfferingTeachingDetail detail : this.details) {
			if (detail.getOffering().getName().equals(offeringName)) {
				return detail;
			}
		}
		return null;
	}

	public void add(OfferingTeachingDetail detail) {
		this.details.add(detail);
	}

	public double getTotalTeachingHours() {
		double total = 0.0;
		for (OfferingTeachingDetail detail : details)
			total += detail.getTeachingHours();
		return total;
	}

	public int getTotalSessions() {
		int total = 0;
		for (OfferingTeachingDetail detail : details)
			total += detail.getSessions();
		return total;
	}

	public String getTeacher() {
		return teacher;
	}

	public Nationality getNationality() {
		return nationality;
	}

	public LinkedList<OfferingTeachingDetail> getDetails() {
		return details;
	}

	public String getSortName() {
		return sortName;
	}

	public void setSortName(String sortName) {
		this.sortName = sortName;
	}

	public TeacherType getTeacherType() {
		return teacherType;
	}

	public void setTeacherType(TeacherType teacherType) {
		this.teacherType = teacherType;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getMidName() {
		return midName;
	}

	public void setMidName(String midName) {
		this.midName = midName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	public Long getTeacherId() {
		return teacherId;
	}

	public void setTeacherId(Long id) {
		this.teacherId = id;
	}
}